﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;

namespace System.Windows.Forms.Calendar
{
    public class CalendarItemComparer: IComparer<CalendarItem>
    {
        public int Compare(CalendarItem x, CalendarItem y)
        {
            /* 
             * If X > Y return 1
             * if X < Y return -1
             * if X = Y return 0
            */

            if (x.StartDate.Day > y.StartDate.Day)
            {
                return 1;
            }
            else if (x.StartDate.Day < y.StartDate.Day)
            {
                return -1;
            }

            //Days are the same so compare hours

            if (x.StartDate.Hour > y.StartDate.Hour)
            {
                return 1;
            }
            else if (x.StartDate.Hour < y.StartDate.Hour)
            {
                return -1;
            }

            //Hours are the same so compare minutes
            if (x.StartDate.Minute > y.StartDate.Minute)
            {
                return 1;
            }
            else if (x.StartDate.Minute < y.StartDate.Minute)
            {
                return -1;
            }
            
            //Day, Hour and Minute are the same so compare End Date Hours

            if (x.EndDate.Hour > y.EndDate.Hour)
            {
                return 1;
            }
            else if (x.EndDate.Hour < y.EndDate.Hour)
            {
                return -1;
            }

            //End hours or the same so compare minutes
            if (x.EndDate.Minute > y.EndDate.Minute)
            {
                return 1;
            }
            else if (x.EndDate.Minute < y.EndDate.Minute)
            {
                return -1;
            }
            //Identical items so return 0
            return 0;
        }
    }
}
